package com.zzdn.mqtool.utils;

import org.apache.commons.lang.StringUtils;

import javax.servlet.http.HttpServletRequest;

public class IPTool {

   public static String getClientIp(HttpServletRequest request){
       String ip = request.getRemoteHost();
       if (StringUtils.isEmpty(ip)){
           ip = request.getRemoteAddr();
       }
       if (StringUtils.isEmpty(ip))
           ip =  request.getRemotePort()+"";
       return ip;
   }

    public static int getClientPort(HttpServletRequest request){
       int port = request.getRemotePort();
       return port;
    }

    public static String getClientUser(HttpServletRequest request){
        String user = request.getRemoteUser();
        return user;
    }

}
